package com.greedy.bulls.stock.user.controller;

import com.greedy.bulls.stock.common.exception.ComponentException;
import com.greedy.bulls.stock.entity.user.TradeUser;
import com.greedy.bulls.stock.user.service.IStockUserService;
import com.greedy.stock.common.web.vo.ApiRespResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Yanxy
 * @Date: Created in:2023-07-29
 * Description: 用户服务控制器StockUserController
 */
@RestController()
@RequestMapping("/user")
@Log4j2
@Validated
public class StockUserController {

    @Autowired
    private IStockUserService stockUserService;

    /**
     * 用户登陆接口
     *
     * @param userNo  用户账号
     * @param userPwd 用户密码
     * @return 用户对象
     */
    @RequestMapping("/userLogin")
    public ApiRespResult userLogin(@RequestParam("userNo") String userNo, @RequestParam("userPwd") String userPwd) {

        ApiRespResult result;
        try {
            // 用户登陆逻辑处理
            TradeUser tradeUser = stockUserService.userLogin(userNo, userPwd);
            result = ApiRespResult.success(tradeUser);
        } catch (ComponentException e) {
            log.error(e.getMessage(), e);
            result = ApiRespResult.error(e.getErrorCodeEnum());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result = ApiRespResult.sysError(e.getMessage());
        }
        return result;
    }

}